<!--
 * @Descripttion: 
 * @version: 
 * @Author: Jf W
 * @Date: 2021-08-13 11:23:32
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-08-13 13:50:19
-->
<template>
  <div>
    <el-form-item
      prop="climb_cert"
      class="all-form"
    >
      <el-upload
        ref="upload"
        class="upload-demo"
        action="api/files_process/"
        :http-request="methods.fileUpload"
        :file-list="fileList"
        :auto-upload="true"
        :show-file-list="true"
        :on-remove="methods.handleRemove"
      >
        <el-button
          slot="trigger"
          size="small"
          type="primary"
          @click="methods.setName('climb_cert')"
        >
          上传附件
        </el-button>
      </el-upload>
    </el-form-item>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, reactive } from 'vue'

export default defineComponent({
  setup() {
    const fileName = ref('')
    const fileList = reactive([])
    const calculatType = ref('type')
    const dialogImageUrl = ref('')
    const dialogVisible = ref(false)
    const methods = reactive({
      setName(name: string) {
        fileName.value = name
      },
      fileUpload(param: any) {
        const fd = new FormData()
        fd.append('file', param.file)// 传文件
        fd.append('type', calculatType.value)// 传文件
        // axios({
        //   method: 'post',
        //   url: '/api/files_process/',
        //   headers: {
        //     'Authorization': this.token,
        //     'content-type': 'multipart/form-data; boundary=<calculated when request is sent>'
        //   },
        //   data: fd
        // }).then((res: any) => {
        //   calculatForm.value[fileName.value] = res.data.data.file
        //   if (res.data.code === 200) {
        //     ElMessage.success({
        //       message: '上传成功',
        //       type: 'success'
        //     })
        //     loading.close()
        //   }
        // })
      },
      handleRemove(file: any, fileList: any) {
        console.log(file, fileList)
      }
    })

    return {
      fileName,
      fileList,
      calculatType,
      methods
    }
  }
})
</script>
  
<style lang="scss" scoped>
:deep .el-form-item__label {
  display: none;
}
.all-form {
  width: 50%;
  .upload-demo {
    display: flex;
    justify-content: flex-end;
  }
}
</style>